//
//  AIGirlHomeNavView.swift
//  AIGirl
//
//  Created by Rae on 2023/12/27.
//

import UIKit

class AIGirlHomeNavView: UIView {

    private lazy var titleLabel = c_make_ex(UILabel.self)
        .color(.white).font(18.font_bold).end()
     var diamondButton = UIIconButton(style: .trailing(itemSpace: 5))
    
    var title:String = ""{
        didSet{
            titleLabel.text = title
        }
    }
    
    var showPreviewClosure: (() -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        subviews{
            titleLabel
            diamondButton
        }
        
        titleLabel.leading(15).top(12.5)
        diamondButton.trailing(10).top(9).height(30).width(90)
        
        diamondButton.style { v in
            v.setTitleColor(.white, for: .normal)
//            v.setTitle("688", for: .normal)
            v.setImage("AIGirl_Home_diamond".toImage, for: .normal)
            v.iconSize = CGSize(width: 22, height: 22)
            v.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10.5, bottom: 0, right: 7.5)
            v.backgroundColor = "#A7A7A7".toColor.alpha(0.2)
            v.titleLabel?.font = 18.font_semiBold
            v.layer.cornerRadius = 15
            v.layer.masksToBounds = true
            let money = GlobalTool.userModel?.money ?? 0
            v.setTitle("\(money)", for: .normal)
        }
        NotificationCenter.default.addObserver(forName: .userBalanceChanged, object: nil, queue: nil) { noti in
            let money = GlobalTool.userModel?.money ?? 0
            self.diamondButton.setTitle("\(money)", for: .normal)
        }
        diamondButton.addTarget(self, action: #selector(clickDiamondButton), for: .touchUpInside)
    }
    
    @objc private func clickDiamondButton(){
        showPreviewClosure?()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
